package com.james.codeauto.common;


import java.util.HashMap;
import java.util.Map;


public class PropertiesComponentWarpper {
    public static boolean useIntellijIdea = true;
    private static PropertiesComponentWarpper _p;
    private static Map<String, Object> values = new HashMap<>();

    public static PropertiesComponentWarpper getInstance() {
        if (_p == null) {
            _p = new PropertiesComponentWarpper();
        }
        return _p;
    }

    private static IPropertiesComponent getInstanceFactory() {
        IPropertiesComponent iPropertiesComponent = null;
        if (useIntellijIdea) {
            iPropertiesComponent = new PropertiesComponentImp();
        } else {

        }
        return iPropertiesComponent;
    }

    public void setValue(String name, String value) {
        if (!useIntellijIdea) {
            values.put(name, value);
            return;
        }
        getInstanceFactory().setValue(name, value);
    }

    public String getValue(String name) {
        if (!useIntellijIdea) {
            return (String) values.get(name);
        }
        return getInstanceFactory().getValue(name);
    }

    public int getOrInitInt(String name, int defaultValue) {
        if (!useIntellijIdea) {
            Integer data = (Integer) values.get(name);
            if (data == null) {
                data = defaultValue;
            }
            return data;
        }
        return getInstanceFactory().getOrInitInt(name, defaultValue);
    }

    public String getValue(String name, String defaultValue) {
        if (!useIntellijIdea) {
            String data = (String) values.get(name);
            if (data == null) {
                data = defaultValue;
            }
            return data;
        }
        return getInstanceFactory().getValue(name, defaultValue);
    }

    public Boolean getBoolean(String name, boolean defaultValue) {
        if (!useIntellijIdea) {
            Boolean data = (Boolean) values.get(name);
            if (data == null) {
                data = defaultValue;
            }
            return data;
        }
        return getInstanceFactory().getBoolean(name, defaultValue);
    }
}
